package com.itcast.donkey.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.adapters.TravelAdapter;
import com.itcast.donkey.fragments.ToolBoxDomesticFragment;
import com.itcast.donkey.fragments.ToolBoxOverseasFragment;

import java.util.ArrayList;

/**
 * Created by lanouhn on 16/9/3.
 */
public class ToolBoxAreaActivity extends AppCompatActivity implements View.OnClickListener {
    private LinearLayout linScenicSpot;
    private ImageView backScenicApot;
    private ImageView ivChanScenicSpot;
    private TextView tvTitleScenicSpot;
    private TabLayout tabToolbpxArea;
    private ViewPager viewpagerToolboxArea;

    private ToolBoxDomesticFragment domesticFragment;
    private ToolBoxOverseasFragment overseasFragment;

    private String[] tabs = {"国外", "国内"};
    private ArrayList<Fragment> fragments = new ArrayList<Fragment>();

    private TravelAdapter adapter;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toolbox_area);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        linScenicSpot = (LinearLayout) findViewById(R.id.lin_scenic_spot);
        backScenicApot = (ImageView) findViewById(R.id.back_scenic_apot);
        ivChanScenicSpot = (ImageView) findViewById(R.id.iv_chan_scenic_spot);
        tvTitleScenicSpot = (TextView) findViewById(R.id.tv_title_scenic_spot);
        tabToolbpxArea = (TabLayout) findViewById(R.id.tab_toolbpx_area);
        viewpagerToolboxArea = (ViewPager) findViewById(R.id.viewpager_toolbox_area);
    }

    private void initData() {
        domesticFragment = new ToolBoxDomesticFragment();
        overseasFragment = new ToolBoxOverseasFragment();
        fragments.add(overseasFragment);
        fragments.add(domesticFragment);
        adapter = new TravelAdapter(getSupportFragmentManager(), fragments, tabs);
        viewpagerToolboxArea.setAdapter(adapter);
        tabToolbpxArea.setSelectedTabIndicatorColor(Color.BLUE);
        tabToolbpxArea.setupWithViewPager(viewpagerToolboxArea);
    }

    private void initEvent() {
        backScenicApot.setOnClickListener(this);
        ivChanScenicSpot.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_scenic_apot:
            case R.id.iv_chan_scenic_spot:
                finish();
                break;
        }

    }
}
